package com.hikvision.cms.controller;

import com.hikvision.cms.Result;
import com.hikvision.cms.ResultUtil;
import com.hikvision.cms.common.util.EncrypDES;
import com.hikvision.cms.dto.EventDisDto;
import com.hikvision.cms.service.PlaneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping({"/"})
public class PlaneController {
    @Autowired
    private PlaneService planeService;
    private String token = "establishment2019";

    @RequestMapping({"/info/get"})
    public Result getInfo(@RequestParam(value = "nonce", required = true) String nonce, @RequestParam(value = "time", required = true) String time, @RequestParam(value = "sign", required = true) String sign) {

        String mds = EncrypDES.getMD5("nonce=" + nonce + "&time=" + time + "&token=" + this.token);
        if (sign != null && mds.equals(sign)) {
            EventDisDto eventDisDto = this.planeService.getEventDisDtoBean();
            return ResultUtil.success(eventDisDto);
        }
        return ResultUtil.error(Integer.valueOf(10010), "验证失败");
    }

    @RequestMapping({"/info/delete"})
    public Result deleteInfo(@RequestParam(value = "id", required = true) Integer id, @RequestParam(value = "nonce", required = true) String nonce, @RequestParam(value = "time", required = true) String time, @RequestParam(value = "sign", required = true) String sign) {
        String mds = EncrypDES.getMD5("id=" + id + "&nonce=" + nonce + "&time=" + time + "&token=" + this.token);
        if (sign != null && mds.equals(sign)) {
            Integer integer = this.planeService.deleteById(id);
            return ResultUtil.success(Boolean.valueOf((integer.intValue() > 0)));
        }
        return ResultUtil.error(Integer.valueOf(10010), "验证失败");
    }

    @RequestMapping({"/info/test"})
    public Result test() {
        return ResultUtil.success();
    }
}

